//
//  UIBarButtonItem+Extension.swift
//  仿微博
//
//  Created by a。 on 16/9/20.
//  Copyright © 2016年 a。. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    
    //遍历构造函数创建btn
    convenience init(title : String , imageName : String? = nil ,target : Any?, action :Selector) {
        
        self.init()
        
        
        
        let btn = UIButton()
        //        btn.addTarget(target, action: #selector(pushAction), for: .touchUpInside)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if imageName != nil {
            btn.setImage(UIImage(named: imageName!), for: .normal)
        }
        
        btn.setTitle(title, for: .normal)
        //设置按钮不同状态下字体的颜色
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        //  设置字体大小
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        btn.sizeToFit()
        customView = btn
        
    }
 
    
}
